<template>
	<view>
		<u-cell-group>
			<u-cell :value="item.deal_text" center v-for="item in list" :key="item.id">
				<view slot="title" class="u-slot-title">
					<text class="u-cell-text">{{item.nickname}}</text>
				</view>
				<view slot="label" class="u-slot-label">
					<view style="color:#909193">客户来源： {{item.scource.name}}</view>
					<u-button type="primary" :customStyle="btnStyle" size="mini" text="还原"
						@click="getBusinessData(item)"></u-button>
					<u-button type="error" :customStyle="btnStyle" size="mini" text="删除"
						@click="getBusinessData(item, 'del')"></u-button>
				</view>
			</u-cell>
		</u-cell-group>
		<!-- 删除确认框 -->
		<u-modal :show="show" :content='content' showCancelButton @cancel="show = false"
			@confirm="confirmDel"></u-modal>
		<!-- 还原确认框 -->
		<u-modal :show="show1" :content='content1' showCancelButton @cancel="show1 = false"
			@confirm="confirmRestore"></u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				content: '确认是否删除客户？',
				show1: false,
				content1: '确认是否还原客户？',
				btnStyle: {
					width: '10%',
					display: "inline-block",
					marginRight: '5px',
					marginTop: '10px',
					lineHeight: '20px'
				},
				list: [],
				busid: 0,
			}
		},
		onReady() {
			this.$u.auth.check();
			this.getRecycleData()
		},
		methods: {
			async getRecycleData() {
				let result = await this.$u.api.manage.recycleIndex()
				if (result.code == 1) {
					this.list = result.data
				}
			},
			getBusinessData(item, val) {
				this.busid = item.id
				if (val == 'del') {
					this.content = '确认是否删除' + item.nickname + '客户'
					this.show = true
				} else {
					this.content1 = '确认是否还原' + item.nickname + '客户'
					this.show1 = true
				}
			},
			async confirmDel() {
				this.show = false
				let result = await this.$u.api.manage.recycleDel({
					id: this.busid
				})
				if (result.code == 1) {
					this.getRecycleData()
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg
					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			},
			async confirmRestore() {
				this.show1 = false
				let result = await this.$u.api.manage.recycleRestore({
					id: this.busid
				})
				if (result.code == 1) {
					this.getRecycleData()
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg
					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			}
		},
	}
</script>

<style>
</style>